<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>$课堂练习$</title>
</head>
<body>
<input type="button" value="创建表格" id="btn">
<div id="dv"></div>
<script src="../common.js"></script>
<script>
    var arr = [
        {name: "百度", href: "https://www.baidu.com"},
        {name: "腾讯", href: "https://www.qq.com"},
        {name: "优酷", href: "https://www.youku.com"},
        {name: "新浪", href: "https://www.sina.com.cn/"},
    ]
    my$("btn").onclick = function () {
        //创建table加入到div中
        var tableObj = document.createElement("table");
        tableObj.border = "1";
        tableObj.cellPadding = "0";
        tableObj.cellSpacing = "0";
        my$("dv").appendChild(tableObj);
        //创建行，把行加入到table中
        for (var i = 0; i < arr.length; i++) {
            var dt = arr[i]; //每个对象
            var trObj = document.createElement("tr");
            tableObj.appendChild(trObj);
            //创建第一个列，然后加入到行中
            var td1 = document.createElement("td");
            td1.innerText = dt.name;
            trObj.appendChild(td1);
            //创建第二个列
            var td2 = document.createElement("td");
            td2.innerHTML = "<a href=" + dt.href + ">" + dt.name + "</a>";
            trObj.appendChild(td2);
        }
    }
</script>
</body>
</html>